using System;
using System.IO;

using OpenEdge.Utility;

namespace OpenEdge.DatabaseEngineering.Generate	
{
	/// <summary>
	/// Summary description for CodeWriter.
	/// </summary>
	public class DefinitionWriter : Writer
	{

		public DefinitionWriter() 
		{
		}

		public DefinitionWriter(string filePath) 
		{
			this.Open(filePath);
		}

		public void Open(string filePath) 
		{
			this.fs = new FileStream(filePath,
				System.IO.FileMode.Create,
				System.IO.FileAccess.ReadWrite,
				System.IO.FileShare.Read);

			this.sw = new StreamWriter(this.fs);

			this.sw.AutoFlush = true;		
		}

		public void Generate_Complete()
		{
			int length = (int) this.fs.Length + 40;
			this.sw.WriteLine(".");
			this.sw.WriteLine("PSC");
			this.sw.WriteLine("cpstream=ISO8859-1");
			this.sw.WriteLine(".");
			this.sw.WriteLine("{0,10:D10}",length);
			/*
			this.sw.Close();
			this.fs.Close();
			*/
		}

		public void Close()
		{
			this.sw.Close();
			this.fs.Close();
		}

		public new void WriteHandler(string writeString)
		{
			this.sw.Write(writeString);
		}

		public new void WriteLineHandler(string writeString)
		{
			this.sw.WriteLine(writeString);
		}

	}
}
